﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Global;
using Microsoft.Win32;

namespace Global
{
    public class Utility
    {
        public static RegistryKey CreateRegistryKey()
        {
            var regMySoft = Registry.CurrentUser.OpenSubKey(Constant.REGISTRY.ENGLISH_REMINDER);
            if (regMySoft == null)
            {
                regMySoft = Registry.CurrentUser.CreateSubKey(Constant.REGISTRY.ENGLISH_REMINDER);
                if (regMySoft != null)
                {
                    var fieldKey = regMySoft.CreateSubKey(Constant.REGISTRY.SETTINGS);

                    if (fieldKey != null)
                    {
                        fieldKey.SetValue(Constant.REGISTRY.VOCABULARY,
                                          (Default.SETTINGS.IS_VOCABULARY == true) ? "1" : "0");
                        fieldKey.SetValue(Constant.REGISTRY.NOTE, (Default.SETTINGS.IS_NOTE == true) ? "1" : "0");
                        fieldKey.SetValue(Constant.REGISTRY.DISPLAY_TIME, Default.SETTINGS.DISPLAY_TIME.ToString());
                        fieldKey.SetValue(Constant.REGISTRY.WAITING_TIME, Default.SETTINGS.WAITING_TIME.ToString());
                        fieldKey.SetValue(Constant.REGISTRY.BEFORE_DATE, string.Empty);
                        fieldKey.SetValue(Constant.REGISTRY.AFTER_DATE, string.Empty);
                        fieldKey.SetValue(Constant.REGISTRY.IS_BEFORE_DATE_CHECKED,
                                          (Default.SETTINGS.IS_BEFORE_DATE_CHECKED == true) ? "1" : "0");
                        fieldKey.SetValue(Constant.REGISTRY.IS_AFTER_DATE_CHECKED,
                                          (Default.SETTINGS.IS_AFTER_DATE_CHECKED == true) ? "1" : "0");
                        fieldKey.SetValue(Constant.REGISTRY.CURRENT_FILE_PATH, string.Empty);
                        fieldKey.SetValue(Constant.REGISTRY.CURRENT_FILE_NAME, string.Empty);
                    }
                }
            }
            return regMySoft;
        }

        public static int RateIdToNumber(string id)
        {
            switch (id)
            {
                case "R1":
                    return Constant.RATE.R1;
                case "R2":
                    return Constant.RATE.R2;
                case "R3":
                    return Constant.RATE.R3;
                case "R4":
                    return Constant.RATE.R4;
                case "R5":
                    return Constant.RATE.R5;
                default:
                    return -1;
            }
        }
    }
}
